using System;
using System.Collections;
using SecuBat.Common;
using SecuBat.Threading;

namespace SecuBat.Work
{
	/// <summary>
	/// Summary description for WorkQueue.
	/// </summary>
	public class WorkQueue : SharedData
	{
		private const int INITIAL_QUEUE_SIZE = 1000;
		private Queue _queue;

		public WorkQueue()
		{
			_queue = new Queue(INITIAL_QUEUE_SIZE);
		}

		public void Enqueue(Task task)
		{
			WriteLock();
			_queue.Enqueue(task);
			WriteRelease();
		}

		public Task Dequeue()
		{
			WriteLock();
			object o = _queue.Dequeue();
			WriteRelease();
			return o as Task;
		}

		public void Clear()
		{
			WriteLock();
			_queue.Clear();
			WriteRelease();
		}

		public Task Peek()
		{
			ReadLock();
			object o = _queue.Peek();
			ReadRelease();
			return o as Task;
		}

		public int Count
		{
			get
			{
				ReadLock();
				int count = _queue.Count;
				ReadRelease();
				return count;
			}
		}
	}
}
